import { EventHandler, Nodes } from '@knno/dom';

export type ExtendEventHandler<M extends Record<keyof M, Event>, K extends keyof M, O extends Nodes> = (
	this: O,
	event: M[K]
) => void;

export interface ExtendEvents<M extends Record<keyof M, Event>, O extends Nodes> {
	on<K extends keyof M>(
		event: K,
		listener: ExtendEventHandler<M, K, O>,
		options?: boolean | AddEventListenerOptions
	): this;
	on<K extends keyof HTMLElementEventMap>(
		event: K,
		listener: EventHandler<K, O>,
		options?: boolean | AddEventListenerOptions
	): this;
	off<K extends keyof M>(
		event: K,
		listener: ExtendEventHandler<M, K, O>,
		options?: boolean | AddEventListenerOptions
	): this;
	off<K extends keyof HTMLElementEventMap>(
		event: K,
		listener: EventHandler<K, O>,
		options?: boolean | AddEventListenerOptions
	): this;
}
